const pool = require("@/db");
const table = require("@/db/table");

exports.createNbThing = async (row) => {
  const result = await pool
    .insert(table.NBTHING, {
      ...row,
      created_at: new Date(),
      updated_at: new Date(),
    })
    .execute();
  return result.insertId;
};

exports.createNbThings = async (rows) => {
  const result = await pool
    .insert(table.NBTHING, rows)
    .column("created_at", new Date()) // 循环赋值给每一行数据
    .column("updated_at", new Date())
    .execute();
  return result;
};

exports.getNbThings = async ({ page_index = 1, page_size = 20 }) => {
  return await pool
    .select("*")
    .from(table.NBTHING)
    .orderby("start_at desc")
    .queryListWithPaging(page_index, page_size);
};
